<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.List"%>
<%@page import="com.model.Menu"%>
<%@page import="com.model.Role"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PayChannel</title>
<link href="styles/general.css" rel="stylesheet" type="text/css">
<link href="styles/main.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/validator.js"></script>
<script>
function txcheck(){
	return formvalidator("all");
}
function formvalidator(obj)
{
	var controlId = "all";
	 if (typeof(obj) != "string" )
	 {
		 controlId = obj.id;
	 }
	if(controlId=="all" || controlId=="model.roleName")
	{
		if(Utils.trim(document.getElementById("model.roleName").value)=="")
		{
			document.getElementById("CompareValidator1").style.visibility="visible";
			return false;
		}
		else
		{
			document.getElementById("CompareValidator1").style.visibility="hidden";
		}
	}
	return true;
}
</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="role_save.do?type=<s:if test="type.equals('upd')">update</s:if><s:else>add</s:else>" onsubmit="return txcheck();">
 <input type="hidden" name="model.id" id="model.id" value="<s:property value="model.id"/>" />
 <h1>
        <span class="action-span"><a href="role_list.do">角色列表</a></span> <span
            class="action-span1"><a href="">
                首页</a> </span><span id="search_id" class="action-span1">- 角色管理 </span>
        <div style="clear: both">
        </div>
    </h1>
    <div style="margin-bottom: 5px;" class="list-div">
        <table width="100%" cellspacing="1" cellpadding="3">
            <tbody>
            	<tr>
                    <th colspan="2">
                      	  基本信息
                    </th>
                </tr>
            	<tr id="jmn">
					<td class="label">
       				角色名称：
                    </td>
					<td>
                       <input name="model.roleName" type="text" id="model.roleName" onblur="formvalidator(this)" value="<s:property value="model.roleName"/>"/><span
                           class="require-field">*</span>&nbsp;
                        <span id="CompareValidator1" style="color:Red;visibility:hidden;">不能为空</span><br />
                    </td>
				</tr>
				<tr id="jmn">
					<td class="label">
       				权限：
                    </td>
					<td>
                       <table>
					    	<%
					  	List<Menu> list= (List<Menu>)request.getAttribute("menuList");
					    Role menumodel = (Role)request.getAttribute("model");
					   	if(menumodel==null)
					   		menumodel = new Role();
					  	int count = 0;
					  	if(list!=null && list.size()>0)
					  	{
					  		int num=0;
					  		for(Menu menu:list)
					  		{
					  			if("".equals(menu.getParentId())||menu.getParentId().equals("0"))
					  			{
					  				count++;
						  			num=0;
						  			for(Menu menu1:list)
						  			{
						  				
						  				if(menu.getId().equals(menu1.getParentId()))
						  				{
						  					num++;
						  				}
						  			}
						  		%>
						  			<tr>
									    <td rowspan="<%=num %>">
									    	<table>
									    		<tr>
									    		<td width="50%"><input id="menuroleid" name="menuroleid" type="checkbox" value="<%=menu.getId()%>select" 
									    		 <%=(menumodel.getMenuValue()!=null&&("_"+menumodel.getMenuValue()).indexOf("_"+menu.getId()+"select_")>=0)?"checked":"" %>/>
									    		&nbsp;&nbsp;<%=menu.getMenuName() %>
									    		</td>
									    		</tr>
									    	</table>
									    </td>
									    <%
									    int td = 0;
									    for(Menu menu1:list)
							  			{
							  				if(menu.getId().equals(menu1.getParentId()))
						  					{
							  					td++;
							  					if(td==1)
							  					{
							  						%>
							  						<td>
							  							<table>
												    		<tr>
												    		<td width="50%">
												    		<input id="menuroleid" name="menuroleid" type="checkbox" value="<%=menu1.getId() %>select" <%=(menumodel.getMenuValue()!=null&&("_"+menumodel.getMenuValue()).indexOf("_"+menu1.getId()+"select_")>=0)?"checked":"" %>/>
												    		查询&nbsp;&nbsp;<input id="menuroleid" name="menuroleid" type="checkbox" value="<%=menu1.getId() %>update" <%=(menumodel.getMenuValue()!=null&&("_"+menumodel.getMenuValue()).indexOf("_"+menu1.getId()+"update_")>=0)?"checked":"" %>/>修改&nbsp;&nbsp;
												    		 <%=menu1.getMenuName() %></td>
												    		</tr>
												    	</table>
							  						
							  						</td>
							  						<%
							  					}else
							  					{
						  					%>
						  						</tr><tr>
						  						<td>
							  							<table>
												    		<tr>
												    		<td width="50%">
												    		<input id="menuroleid" name="menuroleid" type="checkbox" value="<%=menu1.getId() %>select" <%=(menumodel.getMenuValue()!=null&&("_"+menumodel.getMenuValue()).indexOf("_"+menu1.getId()+"select_")>=0)?"checked":"" %>/>
												    		查询&nbsp;&nbsp;
												    		<input id="menuroleid" name="menuroleid" type="checkbox" value="<%=menu1.getId() %>update" <%=(menumodel.getMenuValue()!=null&&("_"+menumodel.getMenuValue()).indexOf("_"+menu1.getId()+"update_")>=0)?"checked":"" %>/>修改&nbsp;&nbsp;
												    		<%=menu1.getMenuName() %></td>
												    		</tr>
												    	</table>
							  						
							  						</td>
						  					<%
							  					}
						  					}
							  			}
									    %>
									    </tr>
						  		<%
					  			}
					  		}
					  	}%>
					  	</table>
                    </td>
				</tr>
				<tr id="jmn">
					<td class="label">
       				说明：
                    </td>
					<td>
                       <textarea rows="5" cols="40" name="model.remark" id="model.remark"><s:property value="model.remark"/></textarea>
                    </td>
				</tr>
				 <tr>
                    <td colspan="2" align="center">
                     <s:if test="isUpdate.equals('true')">
					    <input type="submit" value=" 确定 " class="button" />
					 </s:if>
                        &nbsp;&nbsp;&nbsp;
                        <input type="reset" value=" 重置 " class="button" />
                    </td>
                </tr>
            </tbody>
   		</table>
   	</div>
<!--Bottom开始-->
    
<div id="footer">
<br />
<s:property value="bottom"/></div>
    <!--Bottom结束-->
</form>
<br />
</body>
</html>